package com.lulufind.lulu.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.google.gson.Gson;
import com.lulufind.lulu.model.Comment;
import com.lulufind.lulu.model.Result;
import com.lulufind.lulu.service.CommentService;
import com.lulufind.lulu.vo.UserCommentVO;

@Controller
@RequestMapping("/comment")
public class CommentController {
	
	@Autowired
	CommentService commentService;
	
	@ResponseBody
	@RequestMapping(value="/addComment",produces="application/json;charset=UTF-8")
	public String addComment(Comment comment, String commentUserToken){
		
		Result<String> rs = commentService.addComment(comment, commentUserToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/delComment",produces="application/json;charset=UTF-8")
	public String delComment(int commentId, int userId, String userToken){
		
		Result<Comment> rs = commentService.delComment(commentId, userId, userToken);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getCommentList",produces="application/json;charset=UTF-8")
	public String getCommentList(int postId, int start, int num){
		
		Result<List<UserCommentVO>> rs = commentService.getCommentList(postId, start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
	
	@ResponseBody
	@RequestMapping(value="/getMyCommentList",produces="application/json;charset=UTF-8")
	public String getMyCommentList(int userId, String userToken, int start, int num){
		
		Result<List<UserCommentVO>> rs = commentService.getCommentListByUserId(userId, userToken, start, num);
		
		Gson gson = new Gson();
		String s = gson.toJson(rs);
		return s;
	}
}
